package sse.Tool.bug;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;

import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.dom4j.DocumentException;

public class BugListMain {

	private static Logger logger = Logger.getLogger(BugListMain.class);
	
	public static void changeListToExcel(String filePath, List<List<String>> list) throws IOException {
		System.out.println("创建Excel。。。");
		// 创建HSSFWorkbook对象
		HSSFWorkbook wb = new HSSFWorkbook();
		// 创建HSSFSheet对象
		HSSFSheet sheet = wb.createSheet("sheet1");
		// 创建HSSFRow对象
		for (int i = 0; i < list.size(); i++) {
			HSSFRow row = sheet.createRow(i);
			List<String> rowValue = list.get(i);
			for (int j = 0; j < rowValue.size(); j++) {
				// 创建HSSFCell对象
				HSSFCell cell = row.createCell(j);
				// 设置单元格的值
				cell.setCellValue(rowValue.get(j));
			}
		}

		// 输出Excel文件
		FileOutputStream output = new FileOutputStream(filePath);
		wb.write(output);
		output.flush();
		wb.close();
	}
	
	public static void main(String[] args) throws DocumentException, IOException {
		
		if (args.length != 2){
			logger.info("Usage:");
			logger.info("java -classpath Tool-0.0.1-SNAPSHOT.jar sse.Tool.bug.BugListMain");			
			return;
		}
		
		String buglistXml = args[0];
		String buglistXls = args[1];
		
		XmlUtil.changeXmlToList(buglistXml);
		changeListToExcel(buglistXls, XmlUtil.ALL_LIST);
	}
}
